<!DOCTYPE html>
<html>

<head>
    <script src="https://cdn.jsdelivr.net/npm/html2canvas@1.0.0-rc.5/dist/html2canvas.min.js"></script>
</head>

<body>
    <div id="capture">
        <h1>Hello World!</h1>
        <p>This is some sample text.</p>
       
    </div>
    <script> 
        html2canvas(document.querySelector("#capture")).then(canvas => { 
            var dataURL = canvas.toDataURL();
            var link = document.createElement("a");
            link.download = "image.png";
            link.href = dataURL;
            link.click(); 
        }); 
    </script>
</body>

</html>